<template>
    <div style="width: 100%;">
        <div v-if="active==1">
            <el-form :inline="true">
                <el-form-item>
                    <el-select v-model="params.tenderId" :value="params.tenderId">
                        <el-option label="招标编号" value=""></el-option>
                        <el-option
                                v-for="tender in tenderPurchasePlanList"
                                :key="tender.id"
                                :label="tender.id"
                                :value="tender.id"
                        ></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-input v-model="params.projectName" placeholder="项目名称" :clearable="true"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-select v-model="params.projectType" :value="params.projectType">
                        <el-option label="项目类型" value=""></el-option>
                        <el-option
                                v-for="projectType in projectTypeList"
                                :key="projectType.typeId"
                                :label="projectType.typeName"
                                :value="projectType.typeId"
                        ></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-select v-model="params.status" :value="params.status">
                        <el-option label="竞标状态" value=""></el-option>
                        <el-option label="待开标" value="1"></el-option>
                        <el-option label="已开标" value="2"></el-option>
                        <el-option label="中标" value="3"></el-option>
                        <el-option label="未中标" value="4"></el-option>
                        <el-option label="已撤销" value="5"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item style="margin-left: 10px">
                    <el-button @click="handleSearch" type="primary">检索</el-button>
                </el-form-item>
            </el-form>

            <el-table :data="pageResult.records">
                <el-table-column label="序号" type="index"></el-table-column>
                <el-table-column label="招标编号" prop="tenderId"></el-table-column>
                <el-table-column label="项目名称" prop="projectName"></el-table-column>
                <el-table-column label="项目类型" prop="projectType"></el-table-column>
                <el-table-column label="报价日期" prop="createdate"></el-table-column>
                <el-table-column label="报价金额(万)" prop="offer">
                    <template slot-scope="scope">
                        {{scope.row.offer/10000}}
                    </template>
                </el-table-column>
                <el-table-column label="状态" prop="status">
                    <template slot-scope="scope">
                        <span v-if="scope.row.status=='1'" style="color: #cf9236;font-weight: 700">待开标</span>
                        <span v-if="scope.row.status=='2'" style="color: #20a0ff;font-weight: 700">已开标</span>
                        <span v-if="scope.row.status=='3'" style="color: green;font-weight: 700">中标</span>
                        <span v-if="scope.row.status=='4'" style="color: red;font-weight: 700">未中标</span>
                        <span v-if="scope.row.status=='5'" style="color: #8c939d;font-weight: 700">已撤销</span>
                    </template>
                </el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-button v-if="scope.row.status=='1' || scope.row.status=='2'" type="text" @click="handleCancel(scope.row)">撤销</el-button>
                        <el-button type="text" v-if="scope.row.status=='3' || scope.row.status=='4'" @click="handleShowDetails(scope.row)">查看详情</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <el-divider></el-divider>

            <el-footer class="case-list-footer">
                <el-pagination
                        style="margin: 10px auto"
                        background
                        layout="total , sizes ,prev, pager, next,jumper"
                        :page-sizes="[5,10,15,20]"
                        :total="pageResult.total"
                        :page-size="pageResult.size"
                        class="pagination"
                        @current-change="handleIndexChange"
                        @size-change="handleSizeChange"
                >
                </el-pagination>
            </el-footer>
        </div>

        <div style="width: 100%;" v-if="active==2">
            <goods-bidding :plan="plan" @back="active=1"></goods-bidding>
        </div>
    </div>
</template>

<script>
    import {TenderBiddingHistoryService} from "../../../model/gs/TenderBiddingHistoryService";
    import {ProjectTypeService} from "../../../model/gs/ProjectTypeService";
    import {TenderPurchasePlanService} from "../../../model/gs/TenderPurchasePlanService";

    const tenderBiddingHistoryService = TenderBiddingHistoryService.getInstance()
    const projectTypeService = ProjectTypeService.getInstance()
    const tenderPurchasePlanService = TenderPurchasePlanService.getInstance()

    const GoodsBidding = () => import('./GoodsBidding.vue')
    export default {
        data() {
            return {
                active:1,
                plan: {},
                params: {
                    tenderId: '',
                    projectName: '',
                    projectType: '',
                    status: '',
                    type: 'we'
                },
                projectTypeList: [],
                tenderPurchasePlanList:[],
                pageResult: []
            }
        },
        methods: {
            getProjectTypeList() {
                projectTypeService.getList().then(response => {
                    if (response.data.code === 0) {
                        this.projectTypeList = response.data.data
                    }
                })
            },
            getTenderPurchasePlanList() {
                tenderPurchasePlanService.list().then(response => {
                    if(response.data.code === 0){
                        this.tenderPurchasePlanList = response.data.data
                    }
                })
            },
            getTenderBiddingHistoryList() {
                tenderBiddingHistoryService.getPageList(this.params).then(response => {
                    if (response.data.code === 0) {
                        this.pageResult = response.data.data
                    }
                })
            },
            handleSearch() {
                this.params.page = 1
                this.getTenderBiddingHistoryList()
            },
            handleIndexChange(index) {
                this.params.page = index
                this.getTenderBiddingHistoryList()
            },
            handleSizeChange(size) {
                this.params.size = size
                this.getTenderBiddingHistoryList()
            },
            handleCancel(row){
                tenderBiddingHistoryService.cancel(row).then(response => {
                    if(response.data.code === 0){
                        this.$message.success({
                            message:'撤销成功',
                            duration:1000
                        })
                        this.getTenderBiddingHistoryList()
                    }
                })
            },
            handleShowDetails(row){
                tenderPurchasePlanService.getById(row.tenderId).then(response => {
                    if(response.data.code === 0){
                        this.plan = response.data.data
                        this.plan.type = 'details'
                        this.active++
                    }
                })
            }
        },
        created() {
            this.getTenderBiddingHistoryList()
            this.getTenderPurchasePlanList()
            this.getProjectTypeList()
        },
        components:{
            GoodsBidding
        }
    }
</script>

<style scoped>

</style>
